package com.mall.permission.service.impl;

import com.mall.permission.model.RoleInfo;
import com.mall.permission.mapper.RoleInfoMapper;
import com.mall.permission.service.IRoleInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 权限信息 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-10-20
 */
@Service
public class RoleInfoServiceImpl extends ServiceImpl<RoleInfoMapper, RoleInfo> implements IRoleInfoService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addRoleInfo(RoleInfo roleinfo){
        return super.save(roleinfo);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String id){
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateRoleInfo(RoleInfo roleinfo){
        return super.updateById(roleinfo);
    }

    @Override
    public RoleInfo getById(String id){
        return super.getById(id);
    }

    @Override
    public List<RoleInfo> selectList(RoleInfo roleinfo){
        return super.list(getQueryWrapper(roleinfo));
    }

    @Override
    public Page<RoleInfo> selectPage(Page<RoleInfo> page, RoleInfo roleinfo){
        return super.page(page, getQueryWrapper(roleinfo));
    }

    public LambdaQueryWrapper<RoleInfo> getQueryWrapper(RoleInfo roleinfo){
        return Wrappers.<RoleInfo>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(roleinfo.getId()), RoleInfo::getId, roleinfo.getId())
            .eq(ObjectUtils.isNotEmpty(roleinfo.getRoleName()), RoleInfo::getRoleName, roleinfo.getRoleName())
            .eq(ObjectUtils.isNotEmpty(roleinfo.getDescription()), RoleInfo::getDescription, roleinfo.getDescription())
        ;
    }
}
